import axios from 'axios';

function get (baseUrl, url, params) {
  return axios({
    url: url,
    method: 'get',
    baseURL: baseUrl,
    headers: {
      'Content-Type': 'application/json'
    },
    params: params
  });
}

function post (baseUrl, url, params) {
  var option = {
      url: url,
      method: 'post',
      baseURL: baseUrl,
      headers: {
        'Content-Type': 'application/json'
      },
      data: params
  };
  return axios(option);
}
function del (baseUrl, url, params) {
  var option = {
    url: url,
    method: 'delete',
    baseURL: baseUrl,
    headers: {
      'Content-Type': 'application/json'
    },
    data: params
  };
  return axios(option);
}

function resolve (rep, clback) {
  var data = rep.data;

  if (rep.status == 200) {
    clback && clback(data);
  }

  return data;
}

module.exports = {
  get,
  post,
  resolve,
  del
};
